<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>

<%

String email = request.getParameter("email");
	
//Timestamp
final String timestamp = String.valueOf(new Date().getTime());

//URL
final String url = request.getRequestURL().toString().replace(request.getRequestURI().substring(1), request.getContextPath()) + "/index.jsp?code="+timestamp+"&email="+email;

// SMTP Authentication settings
final String host = "smtp.gmail.com";
final String user = "laerested.utland.noanswer@gmail.com";
final String pass = "qweasdqweasd9009";
final String port = "465";

// E-Mail settings
final String to = email;
final String from = user;
final String subject = "LUT Account Password";

String userName = "test";
%>

<sql:query var="user" dataSource="jdbc/lut2">
    SELECT * FROM admin_users WHERE email = ?
    <sql:param><%= email %></sql:param>
</sql:query>

<c:set var="review" value="${user.rowsByIndex[0][1]}" scope="request"/>
<c:set var="review2" value="${user.rowsByIndex[0][0]}" scope="request"/>
        <c:choose>
            <c:when test="${ empty review }">
                No reviews for yet. Help us out by adding one! 
                <br><br>
            </c:when>
            <c:otherwise>
                <c:forEach var="review" items="${user.rowsByIndex}">
                    <c:out value="${review[2]}" />
                </c:forEach>
            </c:otherwise>
        </c:choose>


<%

final String mesg = "Account, registered on our service with this e-mail and username: "+request.getAttribute("review2")+", requested accounts password: "+request.getAttribute("review");

Properties props = System.getProperties();
        props.put("mail.smtp.host", host);
        props.put("mail.smtp.socketFactory.port", port);
        props.put("mail.smtp.socketFactory.class",
                "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", port);
            
            Session mailSession = Session.getInstance(props,new javax.mail.Authenticator() { 
				protected PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication(user, pass);
				}
			});
            
 try {

            Message message = new MimeMessage(mailSession);
            message.setContent(mesg, "text/html");
            message.setFrom(new InternetAddress(from));
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
            message.setSubject(subject);
            message.setText(mesg);

            Transport.send(message);

        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
%>


<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="lutstyle.css">
        <title></title>
    </head>
    <body>
    
    
        

    </body>
</html>
